<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::PageTreeNode</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::PageTreeNode</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/origami/page_rb.html">
                origami/page.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Dictionary.html">
                Dictionary
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Class representing a node in a <a href="Page.html">Page</a> tree.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000613">&lt;&lt;</a>&nbsp;&nbsp;
      <a href="#M000612">children</a>&nbsp;&nbsp;
      <a href="#M000611">insert_page</a>&nbsp;&nbsp;
      <a href="#M000610">new</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Configurable.html">Configurable</a></span>
      </div>
    </div>

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Count</td>
          <td>=</td>
          <td class="context-item-value">0</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Kids</td>
          <td>=</td>
          <td class="context-item-value">[]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Count</td>
          <td>=</td>
          <td class="context-item-value">self.children.length</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Count</td>
          <td>=</td>
          <td class="context-item-value">self.Count + 1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Parent</td>
          <td>=</td>
          <td class="context-item-value">self</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Count</td>
          <td>=</td>
          <td class="context-item-value">self.Count + 1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Count</td>
          <td>=</td>
          <td class="context-item-value">self.Kids.length</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Parent</td>
          <td>=</td>
          <td class="context-item-value">self</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000610" class="method-detail">
        <a name="M000610"></a>

        <div class="method-heading">
          <a href="#M000610" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(hash = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000610-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000610-source">
<pre>
     <span class="ruby-comment cmt"># File origami/page.rb, line 177</span>
177:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">hash</span> = {})
178:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span> = <span class="ruby-value">0</span>
179:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span> = []
180: 
181:       <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">hash</span>)
182:       
183:       <span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
184:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000613" class="method-detail">
        <a name="M000613"></a>

        <div class="method-heading">
          <a href="#M000613" class="method-signature">
          <span class="method-name">&lt;&lt;</span><span class="method-args">(pageset)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000613-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000613-source">
<pre>
     <span class="ruby-comment cmt"># File origami/page.rb, line 254</span>
254:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">pageset</span>)
255:       <span class="ruby-identifier">pageset</span> = [<span class="ruby-identifier">pageset</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">pageset</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Array</span>)
256:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;Cannot add anything but Page and PageTreeNode to this node&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">pageset</span>.<span class="ruby-identifier">all?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Page</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">PageTreeNode</span>) }
257: 
258:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
259:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">pageset</span>)
260:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>.<span class="ruby-identifier">length</span>
261:         
262:       <span class="ruby-identifier">pageset</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span> 
263:         <span class="ruby-identifier">node</span>.<span class="ruby-constant">Parent</span> = <span class="ruby-keyword kw">self</span> 
264:       <span class="ruby-keyword kw">end</span>
265:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000612" class="method-detail">
        <a name="M000612"></a>

        <div class="method-heading">
          <a href="#M000612" class="method-signature">
          <span class="method-name">children</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of <a href="Page.html">Page</a> inheriting this tree node.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000612-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000612-source">
<pre>
     <span class="ruby-comment cmt"># File origami/page.rb, line 238</span>
238:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">children</span>
239:       <span class="ruby-identifier">pageset</span> = []
240:      
241:       <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span>.<span class="ruby-identifier">nil?</span>
242:         [ <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span>.<span class="ruby-identifier">value</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>.<span class="ruby-identifier">length</span> ].<span class="ruby-identifier">min</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
243:           <span class="ruby-identifier">node</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">solve</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>[<span class="ruby-identifier">n</span>]
244:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">node</span>
245:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PageTreeNode</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">pageset</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">children</span>) 
246:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Page</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">pageset</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">node</span>
247:           <span class="ruby-keyword kw">end</span>
248:         <span class="ruby-keyword kw">end</span>
249:       <span class="ruby-keyword kw">end</span>
250:       
251:       <span class="ruby-identifier">pageset</span>
252:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000611" class="method-detail">
        <a name="M000611"></a>

        <div class="method-heading">
          <a href="#M000611" class="method-signature">
          <span class="method-name">insert_page</span><span class="method-args">(index, page)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000611-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000611-source">
<pre>
     <span class="ruby-comment cmt"># File origami/page.rb, line 192</span>
192:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">insert_page</span>(<span class="ruby-identifier">index</span>, <span class="ruby-identifier">page</span>)
193:       
194:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">index</span> <span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span>
195:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">IndexError</span>, <span class="ruby-value str">&quot;Invalid index for page tree&quot;</span>
196:       <span class="ruby-keyword kw">end</span>
197: 
198:       <span class="ruby-identifier">count</span> = <span class="ruby-value">0</span>
199:       <span class="ruby-identifier">kids</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Kids</span>
200: 
201:       <span class="ruby-identifier">kids</span>.<span class="ruby-identifier">length</span>.<span class="ruby-identifier">times</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
202:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index</span>
203:           <span class="ruby-identifier">kids</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-identifier">n</span>, <span class="ruby-identifier">page</span>)
204:           <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
205:           <span class="ruby-identifier">page</span>.<span class="ruby-constant">Parent</span> = <span class="ruby-keyword kw">self</span>
206:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
207:         <span class="ruby-keyword kw">else</span>
208:           <span class="ruby-identifier">node</span> = <span class="ruby-identifier">kids</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">kids</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">solve</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">kids</span>[<span class="ruby-identifier">n</span>]
209:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">node</span>
210:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Page</span>
211:               <span class="ruby-identifier">count</span> = <span class="ruby-identifier">count</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
212:               <span class="ruby-keyword kw">next</span>
213:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PageTreeNode</span>
214:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">node</span>.<span class="ruby-constant">Count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">index</span>
215:                 <span class="ruby-identifier">node</span>.<span class="ruby-identifier">insert_page</span>(<span class="ruby-identifier">index</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">count</span>, <span class="ruby-identifier">page</span>)
216:                 <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Count</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
217:                 <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
218:               <span class="ruby-keyword kw">else</span>
219:                 <span class="ruby-identifier">count</span> = <span class="ruby-identifier">count</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">node</span>.<span class="ruby-constant">Count</span>
220:                 <span class="ruby-keyword kw">next</span>
221:               <span class="ruby-keyword kw">end</span>
222:           <span class="ruby-keyword kw">end</span>
223:         <span class="ruby-keyword kw">end</span>
224:       }
225: 
226:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index</span>
227:         <span class="ruby-keyword kw">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">page</span>
228:       <span class="ruby-keyword kw">else</span>
229:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">IndexError</span>, <span class="ruby-value str">&quot;An error occured while inserting page&quot;</span>
230:       <span class="ruby-keyword kw">end</span>
231: 
232:       <span class="ruby-keyword kw">self</span>
233:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>